<?php

/**
 * NOTICE OF LICENSE
 *
 * THIS SOURCE FILE IS PART OF EVEBIT'S PRIVATE PROJECT.
 * 
 * DO NOT USE THIS FILE IN OTHER PLACE.
 *
 * @package   App_Backend
 * @author    Cheng Wei <berlios.o@gmail.com>
 * @version   $$Id: Config.php 20 2010-12-18 09:35:07Z cheng.wei $$
 * @copyright Copyright (c) 2008 Evebit Inc. China (http://www.evebit.com)
 */

/**
 * Resource model for Config
 * 
 * 
 * @see Backend_Model_Entity_Config
 * 
 * @package   App_Backend
 * @author    Cheng Wei <berlios.o@gmail.com>
 * @version   $$Id: Config.php 20 2010-12-18 09:35:07Z cheng.wei $$
 */
class Default_Model_Resource_Config extends Evebit_Model_Mysql_Abstract {
	
	/**
	 * init table
	 */
	protected function _construct() {
		$this->_init('configuration');
	}

	/**
	 * Load configuration from database
	 * 
	 * @return array
	 */
	public function loadConfigurations() {
		$table = $this->getMainTable();
		$db = $this->getReadConnection();
		
		$select = $db->select()->from(array('main_table'=>$table), array('code','value'));
		return $db->fetchPairs($select);
	}
	
    public function getCodeValue($code, $default = null){
		$db = $this->getReadConnection();
		$select = $db->select()->from($this->getMainTable(), array('value'))->where('code = ?', $code);
		if($db->fetchOne($select)){
			return $db->fetchOne($select);
		}else{
			return $default;
		}
	}
	
}